package com.forest.core.util

import java.security.MessageDigest

/**
 *
 * MD5 加密工具
 */
object MD5SecretUtil {



    /**
     * 对String 进行md5签名
     *
     * @param string 输入String
     * @return 基于输入String 进行md5签名后的结果
     */
    fun md5(string: String): String {
        try {
            val hash = MessageDigest.getInstance("MD5").digest(string.toByteArray(charset("UTF-8")))
            val hex = StringBuilder(hash.size * 2)
            for (b in hash) {
                if (b.toInt() and 0xFF < 0x10) {
                    hex.append("0")
                }
                hex.append(Integer.toHexString(b.toInt() and 0xFF))
            }
            return hex.toString()
        } catch (e: Exception) {

        }
        return ""
    }
}
